﻿using System;
using System.IO;
using System.Text;
using System.Web;

namespace WPay.Infrastructure.Unity.H5Pay
{
    public class Log
    {
        //在网站根目录下创建日志目录
        public static string path = AppDomain.CurrentDomain.BaseDirectory + @"\logs\";
        public static object _lock = new object();
        /**
         * 向日志文件写入调试信息
         * @param className 类名
         * @param content 写入内容
         */
        public static void Debug(string className, string content)
        {
            if (WxPayConfig.LOG_LEVENL >= 3)
            {
                WriteLog("DEBUG", className, content);
            }
        }

        /**
        * 向日志文件写入运行时信息
        * @param className 类名
        * @param content 写入内容
        */
        public static void Info(string className, string content)
        {
            if (WxPayConfig.LOG_LEVENL >= 2)
            {
                WriteLog("INFO", className, content);
            }
        }
        public static void Info2(string className, string content)
        {
            WriteLog("INFO", className, content);
        }
        /**
        * 向日志文件写入出错信息
        * @param className 类名
        * @param content 写入内容
        */
        public static void Error(string className, string content)
        {

            WriteLog("ERROR", className, content);

        }
        public static void Error2(string className, string content)
        {

            WriteLog("ERROR", className, content);

        }
        /**
        * 实际的写日志操作
        * @param type 日志记录类型
        * @param className 类名
        * @param content 写入内容
        */
        protected static void WriteLog(string type, string className, string content)
        {
            lock (_lock)
            {
                var name = DateTime.Now.ToString("yyyy-MM-dd");
                string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");//获取当前系统时间
                string write_content = time + " " + type + " " + className + ": " + content;
               SubmitLog.Log("", write_content);
            }
        }
    }
}
